package com.topfinance.payment.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.frame.util.StringUtil;
import com.topfinance.payment.dto.TCfgConfigSetDto;
import com.topfinance.payment.ebo.TCfgConfigSetEbo;
import com.topfinance.payment.service.ITCfgConfigSetMgr;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class TCfgConfigSetMgrImpl extends HibernateEntityDao<TCfgConfigSetEbo> implements ITCfgConfigSetMgr {

	private static final Log log = LogFactory.getLog(TCfgConfigSetMgrImpl.class);
	
	//获得传输协议	
	public TCfgConfigSetEbo getTCfgConfigSet(Integer oid) throws AppException{
		return (TCfgConfigSetEbo)get(oid);
	}

	public void deleteTCfgConfigSet(Integer oid) throws AppException{
		removeById(TCfgConfigSetEbo.class,oid);
	}

	//获得传输协议列表
	public List<TCfgConfigSetEbo> getAllConfigSet(String provider) throws AppException{
		String hql = " from TCfgConfigSetEbo t " ;
		String where = "";
		if(StringUtil.isNotNullStr(provider))
			where = " t.provider ='" + provider + "'";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}
	
	//根据类型获得属性和默认值
	public List<TCfgConfigSetDto> getDefCfgSet(Integer poid,String provider) throws AppException{
		String hql = "";
		String where = "";
		 //如果t_cfg_config已有值，读取
		if(poid != null){
			hql = "select new com.topfinance.payment.dto.TCfgConfigSetDto(c.id,c.cfgName,c.cfgValue) from TCfgConfigEbo c where c.poid=" + poid ;
			return find(hql);
		}
		hql = "select new com.topfinance.payment.dto.TCfgConfigSetDto(c.cfgKey,c.cfgDftVal) from TCfgConfigSetEbo c ";
		if(StringUtil.isNotNullStr(provider))
			where = " c.provider ='" + provider + "'";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}
	
}
